package com.wlcj.www.web.news;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;

import com.wlcj.util.RedisUtil;
import com.wlcj.www.model.main.Channel;
import com.wlcj.www.model.main.Content;
import com.wlcj.www.model.main.Penster;
import com.wlcj.www.web.BaseAction;

public class NewsAction extends BaseAction{

	public void index(){
		// 广告位
		int[] guanggaoweiids = new int[]{2453,2454};
		List<Content> guanggaowei = Content.dao.getListByIds(guanggaoweiids);
		
		// 未来网评 
		List<Content> wangping = Content.dao.getListByChannelId(82, 0,1);
		// 大佬访谈 84
		List<Content> con = Content.dao.getListByChannelId(84, 0, 1);
		// 漫画金融
		List<Content> manhua = Content.dao.getListByChannelId(40, 0,1);
		setAttr("dalao", con);
		setAttr("wangping", wangping);
		setAttr("manhua", manhua);
		setAttr("guanggaowei", guanggaowei);
		renderJsp("news.jsp");
	}
	
	public void pingtaidongtai(){
		int channel_id = getParaToInt("channel_id");
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("pingtaidongtailist");
		if(CollectionUtils.isEmpty(list)){
			list = Content.dao.getListByChannelId(channel_id, 0,count);
		}
		setAttr("list", list);
		renderJsp("pingtaidongtai.jsp");
	}
	
	public void caizhiyuedu(){
		int channel_id = getParaToInt("channel_id");//176
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("caizhiyuedulist");
		if(CollectionUtils.isEmpty(list)){
			list = Content.dao.getListByChannelId(channel_id, 0,count);
		}
		setAttr("list", list);
		renderJsp("caizhiyuedu.jsp");
	}
	
	public void wangdaizhuanti(){
		int channel_id = getParaToInt("channel_id");//11
		int count = getParaToInt("count");
		List<Content> list = Content.dao.getListByChannelId(channel_id, 0,count);
		if(CollectionUtils.isNotEmpty(list)){
			setAttr("one", list.get(0));
			setAttr("list", list);
		}
		
		renderJsp("wangdaizhuanti.jsp");
	}
	
	public void wangqing(){
		int channel_id = getParaToInt("channel_id");//79
		int count = getParaToInt("count");
		List<Content> list = RedisUtil.get("wangqingjianceList");
		if(CollectionUtils.isEmpty(list)){
			list = Content.dao.getListByChannelId(channel_id, 0,count);
		}
		setAttr("list", list);
		renderJsp("wangqing.jsp");
	}
	
	public void zhuanlan(){
		int channel_id = getParaToInt("channel_id");//174
		int count = getParaToInt("count");
		List<Penster> list = Penster.dao.getListByChannelId(channel_id, 0,count);
		setAttr("list", list);
		renderJsp("zhuanlan.jsp");
	}
	
	public void tuwentuijian(){
		// 图文+推荐
		List<Content> list = Content.dao.getTuwenTuijian("rest", 0, 3);
		setAttr("list", list);
		renderJsp("tuwentuijian.jsp");
	}
	public void getList(){
		// 行业观潮  181  // 平台动态  182 // 政策法规  183  // 公告活动  184
		// 能见度  185  // 一号曝光   186  // 数据研究  187   // 网贷国际  188
		// 即时滚动
		Map<String,List<Content>> map = new HashMap<String,List<Content>>();
		List<Channel> chanlist = Channel.dao.getChannelsByParentId(88);
		for(int i=0;i<chanlist.size();i++){
			List<Content> clist = Content.dao.getListByChannelPath(chanlist.get(i).getStr("channel_path"), 0, 10);
			/*for (int j = 0; j < clist.size(); i++) {
				Content c=clist.get(j);
				c.put("sort_date_display", DataUtil.timeTop(String.valueOf(c.get("sort_date"))));
				List<Tag> tagList = Tag.dao.getList(c.getInt("content_id"));
				c.put("tag_list", tagList);
				clist.set(j, c);
			}*/
			map.put(chanlist.get(i).getInt("channel_id")+"", clist);
		}
		map.put(88+"", Content.dao.getListByChannelPath("rest", 0, 10));
		setAttr("map", map);
		setAttr("navList", chanlist);
		renderJsp("dataList.jsp");
	}
	
	public void getPageList(){
		int start = getParaToInt("start");
		int channel_id = getParaToInt("cid");
		List<Content> con = Content.dao.getListByChannelId(channel_id, start, 10);
		List<Content> list = Content.dao.getTotal(channel_id);
		setAttr("con", con);
		setAttr("size", list.size());
		renderJsp("pageList.jsp");
	}
	
}
